﻿package com.wandian.view.mediator
{
	import com.greensock.TweenLite;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.controller.PrizeCommand;
	import com.wandian.data.GameData;
	import com.wandian.model.UserInfoProxy;
	import com.wandian.model.vo.VIPVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZTiming;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.StopWatch;
	import com.wandian.view.components.ui.AddBtn;
	import com.wandian.view.components.ui.FacePanel;
	import com.wandian.view.components.ui.FriendPanel;
	import com.wandian.view.components.ui.HornPanel;
	import com.wandian.view.components.ui.NationalDayPanel;
	import com.wandian.view.components.ui.PayBagPanel;
	import com.wandian.view.components.ui.RedBagPanel;
	import com.wandian.view.components.ui.ScrollBarTxt;
	import com.wandian.view.components.ui.mingame.sgj.MaxWinPanel;
	import com.wandian.view.components.ui.mingame.zp.ZPPanel;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class VIPPrivilegeMediator extends Mediator
    {
        private var _tabBar:CLZTabBar;
        private var _mcContent:Sprite;
        private var _global:GameData;
        private var _filter:GlowFilterManage;
        public static const NAME:String = "VIPPrivilegeMediator";

        public function VIPPrivilegeMediator(param1:Object = null)
        {
            this._global = GameData.getInstance();
            this._filter = GlowFilterManage.getInstance();
            super(NAME, param1);
            return;
        }

        override public function onRegister() : void
        {
            this._mcContent = new Sprite();
            this.mcVip.addChild(this._mcContent);
            this._mcContent.x = 12;
            this._mcContent.y = 84;
            AddBtn.initBtn(this.mcVip, CLZNoticeName.HIDE_VIP_PRIVILEGE, AddBtn.CLOSE_TWO, "", 4, 1);
            CLZButton.setButton(this.mcVip.pay_btn, GameData.tip["PAY_VIP_TIP"]);
            CLZButton.setButton(this.mcVip.draw_btn, GameData.tip["PRIZE_VIP_DRAW"]);
            this.mcVip.title_txt.text = GameData.tip["VIP_BTN"];
            if (this._global.userInfo.userVo.vip > 0)
            {
                this.mcVip.tip_txt.htmlText = GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["VIP_YES_WELCOME"], "NAME", this._global.userInfo.userVo.name), "NUM", this._global.userInfo.userVo.vip);
                this.mcVip.vipReward_txt.htmlText = GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["VIP_GOLD_TXT"], "VIP", this._global.userInfo.userVo.vip), "NUM", GameData._arrMyPrize[1][1]);
                this.mcVip.pay_btn.visible = false;
                if (GameData._arrMyPrize[1][2] == 1)
                {
                    CLZButton.updateMcText(this.mcVip.draw_btn, GameData.tip["NO_PRIZE"]);
                    this.mcVip.draw_btn.mouseEnable = false;
                    this.mcVip.draw_btn.filters = this._filter.getGrayscale();
                }
                else
                {
                    this.mcVip.draw_btn.filters = [];
                    this.mcVip.draw_btn.mouseEnable = true;
                    this.mcVip.draw_btn.addEventListener(MouseEvent.CLICK, this.onDrawVIPPrizeHandler);
                }
                this.mcVip.draw_btn.visible = true;
            }
            else
            {
                this.mcVip.pay_btn.visible = true;
                this.mcVip.pay_btn.addEventListener(MouseEvent.CLICK, this.onPayHandler);
                this.mcVip.draw_btn.visible = false;
                this.mcVip.tip_txt.htmlText = GameData.replaceStrValue(GameData.tip["VIP_NO_WELCOME"], "NAME", this._global.userInfo.userVo.name);
            }
            var _loc_1:Array = [[this.mcVip.vipIntro_btn, GameData.tip["VIP_INTRO"], true, "0xB8B8B8,0xffffff,0xffffff"], [this.mcVip.vipLevel_btn, GameData.tip["VIP_LEVEL_INTRO"], true, "0xB8B8B8,0xffffff,0xffffff"]];
            this._tabBar = new CLZTabBar(_loc_1);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_1[_loc_2][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
                _loc_2 = _loc_2 + 1;
            }
            this._tabBar.setClickIndex(this.mcVip.vipIntro_btn);
            return;
        }

        private function onPayHandler(event:MouseEvent) : void
        {
            this.sendNotification(CLZNoticeName.ON_PAY_VIP);
            return;
        }

        private function onDrawVIPPrizeHandler(event:MouseEvent) : void
        {
            CLZButton.updateMcText(this.mcVip.draw_btn, GameData.tip["NO_PRIZE"]);
            this.mcVip.draw_btn.mouseEnable = false;
            this.mcVip.draw_btn.filters = this._filter.getGrayscale();
            this.sendNotification(CLZNoticeName.PRIZE_VIP_REWARD_REQ, this._global.userInfo.userVo.vip);
            return;
        }

        private function changeTabBarHandler(event:Event) : void
        {
            var _loc_2:Sprite = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:VIPVo = null;
            GameData.removeNumChildre(this._mcContent);
            switch(event.target.name)
            {
                case "vipIntro_btn":
                {
                    _loc_2 = GameData.getSprite("VIPIntro");
                    _loc_2["vipTxt"].text = GameData.tip["VIP_BTN"];
                    _loc_2["vip1_0_txt"].text = GameData.tip["VIP_TEST_CARD"];
                    _loc_2["vip1_1_txt"].text = GameData.tip["VIP_COMMAND_CARD"];
                    _loc_2["vipBuyInTxt"].text = GameData.tip["VIP_BUYIN_PRICE"];
                    _loc_2["getGoldTxt"].text = GameData.tip["VIP_GET_GOLD"];
                    _loc_2["outToTxt"].text = GameData.tip["VIP_LIST_FLAG_2"];
                    _loc_2["dayGoldTxt"].text = GameData.tip["VIP_DAY_GOLD"];
                    _loc_2["signTxt"].text = GameData.tip["VIP_LIST_FLAG_5"];
                    _loc_2["online_txt"].text = GameData.tip["VIP_LIST_FLAG_4"];
                    _loc_2["bankTxt"].text = GameData.tip["VIP_LIST_FLAG_7"];
                    _loc_2["banTxt"].text = GameData.tip["VIP_LIST_FLAG_8"];
                    _loc_2["BanType1"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType2"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType3"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType4"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType5"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType6"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["BanType7"].text = GameData.tip["VIP_BAN_CARD_USE_INTRO"];
                    _loc_2["TickTxt"].text = GameData.tip["VIP_LIST_FLAG_9"];
                    _loc_2["tickType1"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType2"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType3"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType4"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType5"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType6"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_2["tickType7"].text = GameData.tip["VIP_TICK_CARD_USE_INTRO"];
                    _loc_3 = 7;
                    _loc_4 = 1;
                    while (_loc_4 <= _loc_3)
                    {
                        
                        _loc_5 = GameData.getVIPXMLById(_loc_4);
                        if (this._global.userInfo.userVo.gp != GameData.QZONE_SID)
                        {
                        }
                        if (this._global.userInfo.userVo.gp == GameData.FRIEND_SID)
                        {
                            _loc_2["buyIn" + _loc_4].htmlText = GameData.replaceStrValue(GameData.tip["VIP_NUM_PRICE_Q"], "NUM", _loc_5.cost * 10);
                        }
                        else
                        {
                            _loc_2["buyIn" + _loc_4].htmlText = GameData.replaceStrValue(GameData.tip["VIP_NUM_PRICE"], "NUM", _loc_5.cost);
                        }
                        if (_loc_5.objContent["1"] != null)
                        {
                            if (_loc_5.objContent["2"] != null)
                            {
                                _loc_2["get" + _loc_4].text = _loc_5.objContent["1"].toString();
                                _loc_2["send" + _loc_4].text = _loc_5.objContent["2"].toString();
                            }
                            else
                            {
                                _loc_2["get" + _loc_4].text = _loc_5.objContent["1"].toString();
                                _loc_2["send" + _loc_4].text = "0";
                            }
                        }
                        if (_loc_5.objContent["3"] != null)
                        {
                            _loc_2["day" + _loc_4].text = _loc_5.objContent["3"].toString();
                        }
                        else
                        {
                            _loc_2["day" + _loc_4].text = "0";
                        }
                        if (_loc_5.objContent["4"] != null)
                        {
                            _loc_2["online" + _loc_4].text = "+" + _loc_5.objContent["4"].toString();
                        }
                        else
                        {
                            _loc_2["online" + _loc_4].text = "+0";
                        }
                        _loc_4 = _loc_4 + 1;
                    }
                    break;
                }
                case "vipLevel_btn":
                {
                    _loc_2 = GameData.getSprite("VIPLevelIntro");
                    _loc_2["tip_txt"].text = GameData.tip["VIP_BUYIN_TIP"];
                    _loc_2["sign_txt"].htmlText = GameData.tip["VIP_SIGN_INTRO"];
                    _loc_2["bank_txt"].htmlText = GameData.tip["VIP_BANK_INTRO"];
                    _loc_2["sendGold_txt"].htmlText = GameData.tip["VIP_SEND_GOLD_INTRO"];
                    _loc_2["dayGold_txt"].htmlText = GameData.tip["VIP_DAY_GOLD_INTRO"];
                    if (this._global.userInfo.userVo.vip > 0)
                    {
                        _loc_2["pay_btn"].visible = false;
                    }
                    else
                    {
                        CLZButton.setButton(_loc_2["pay_btn"], GameData.tip["PAY_VIP_TIP"]);
                        _loc_2["pay_btn"].visible = true;
                        _loc_2["pay_btn"].addEventListener(MouseEvent.CLICK, this.onPayHandler);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            this._mcContent.addChild(_loc_2);
            return;
        }

        override public function listNotificationInterests() : Array
        {
            return [CLZNoticeName.HIDE_VIP_PRIVILEGE, CLZNoticeName.ON_PAY_VIP];
        }

        override public function handleNotification(param1:INotification) : void
        {
            switch(param1.getName())
            {
                case CLZNoticeName.HIDE_VIP_PRIVILEGE:
                {
                    facade.removeMediator(VIPPrivilegeMediator.NAME);
                    Texas.I._mcWindosView.removeChildTo(this.mcVip);
                    viewComponent = null;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

        private function get mcVip() : MovieClip
        {
            return viewComponent as MovieClip;
        }

    }
}
